<?php

class Azio_Common
{

    public static function cut_tring_by_char($string, $max_length) {
        if (mb_strlen($string, "UTF-8") > $max_length) {
            $max_length = $max_length - 3;
            $string = mb_substr($string, 0, $max_length, "UTF-8");
            $pos = strrpos($string, " ");
            if ($pos === false) {
                return substr($string, 0, $max_length) . "...";
            }
            return substr($string, 0, $pos) . "...";
        } else {
            return $string;
        }
    }

}